

<!DOCTYPE html>
<html class="writer-html5" lang="zh" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Feed 导出 &mdash; Scrapy 2.3.0 文档</title>
  

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.custom.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.bundle.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-shadow.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-punk.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-noir.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-light.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-borderless.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/micromodal.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/sphinx_rtd_theme.css" type="text/css" />

  
  
  
  

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script src="../_static/js/hoverxref.js"></script>
        <script src="../_static/js/tooltipster.bundle.min.js"></script>
        <script src="../_static/js/micromodal.min.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="请求和响应" href="request-response.html" />
    <link rel="prev" title="项目管道" href="item-pipeline.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home" alt="Documentation Home"> Scrapy
          

          
          </a>

          
            
            
              <div class="version">
                2.3
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">第一步</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intro/overview.html">Scrapy一目了然</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/install.html">安装指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/tutorial.html">Scrapy 教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/examples.html">实例</a></li>
</ul>
<p class="caption"><span class="caption-text">基本概念</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="commands.html">命令行工具</a></li>
<li class="toctree-l1"><a class="reference internal" href="spiders.html">蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="selectors.html">选择器</a></li>
<li class="toctree-l1"><a class="reference internal" href="items.html">项目</a></li>
<li class="toctree-l1"><a class="reference internal" href="loaders.html">项目加载器</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Scrapy shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="item-pipeline.html">项目管道</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Feed 导出</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#serialization-formats">序列化格式</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#json">JSON</a></li>
<li class="toctree-l3"><a class="reference internal" href="#json-lines">杰森线</a></li>
<li class="toctree-l3"><a class="reference internal" href="#csv">CSV</a></li>
<li class="toctree-l3"><a class="reference internal" href="#xml">XML</a></li>
<li class="toctree-l3"><a class="reference internal" href="#pickle">泡菜</a></li>
<li class="toctree-l3"><a class="reference internal" href="#marshal">元帅</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#storages">储藏室</a></li>
<li class="toctree-l2"><a class="reference internal" href="#storage-uri-parameters">存储URI参数</a></li>
<li class="toctree-l2"><a class="reference internal" href="#storage-backends">存储后端</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#local-filesystem">本地文件系统</a></li>
<li class="toctree-l3"><a class="reference internal" href="#ftp">FTP</a></li>
<li class="toctree-l3"><a class="reference internal" href="#s3">S3</a></li>
<li class="toctree-l3"><a class="reference internal" href="#google-cloud-storage-gcs">谷歌云存储（GCS）</a></li>
<li class="toctree-l3"><a class="reference internal" href="#standard-output">标准输出</a></li>
<li class="toctree-l3"><a class="reference internal" href="#delayed-file-delivery">延迟文件传递</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#settings">设置</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#feeds">FEEDS</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-export-encoding">FEED_EXPORT_ENCODING</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-export-fields">FEED_EXPORT_FIELDS</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-export-indent">FEED_EXPORT_INDENT</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-store-empty">FEED_STORE_EMPTY</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-storages">FEED_STORAGES</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-storage-ftp-active">FEED_STORAGE_FTP_ACTIVE</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-storage-s3-acl">FEED_STORAGE_S3_ACL</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-storages-base">FEED_STORAGES_BASE</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-exporters">FEED_EXPORTERS</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-exporters-base">FEED_EXPORTERS_BASE</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-export-batch-item-count">FEED_EXPORT_BATCH_ITEM_COUNT</a></li>
<li class="toctree-l3"><a class="reference internal" href="#feed-uri-params">FEED_URI_PARAMS</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="request-response.html">请求和响应</a></li>
<li class="toctree-l1"><a class="reference internal" href="link-extractors.html">链接提取器</a></li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">设置</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">例外情况</a></li>
</ul>
<p class="caption"><span class="caption-text">内置服务</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="logging.html">登录</a></li>
<li class="toctree-l1"><a class="reference internal" href="stats.html">统计数据集合</a></li>
<li class="toctree-l1"><a class="reference internal" href="email.html">发送电子邮件</a></li>
<li class="toctree-l1"><a class="reference internal" href="telnetconsole.html">远程登录控制台</a></li>
<li class="toctree-l1"><a class="reference internal" href="webservice.html">Web服务</a></li>
</ul>
<p class="caption"><span class="caption-text">解决具体问题</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
<li class="toctree-l1"><a class="reference internal" href="debug.html">调试spiders</a></li>
<li class="toctree-l1"><a class="reference internal" href="contracts.html">蜘蛛合约</a></li>
<li class="toctree-l1"><a class="reference internal" href="practices.html">常用做法</a></li>
<li class="toctree-l1"><a class="reference internal" href="broad-crawls.html">宽爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer-tools.html">使用浏览器的开发人员工具进行抓取</a></li>
<li class="toctree-l1"><a class="reference internal" href="dynamic-content.html">选择动态加载的内容</a></li>
<li class="toctree-l1"><a class="reference internal" href="leaks.html">调试内存泄漏</a></li>
<li class="toctree-l1"><a class="reference internal" href="media-pipeline.html">下载和处理文件和图像</a></li>
<li class="toctree-l1"><a class="reference internal" href="deploy.html">部署蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="autothrottle.html">AutoThrottle 扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">标杆管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="jobs.html">作业：暂停和恢复爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="coroutines.html">协同程序</a></li>
<li class="toctree-l1"><a class="reference internal" href="asyncio.html">asyncio</a></li>
</ul>
<p class="caption"><span class="caption-text">扩展Scrapy</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="architecture.html">体系结构概述</a></li>
<li class="toctree-l1"><a class="reference internal" href="downloader-middleware.html">下载器中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="spider-middleware.html">蜘蛛中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">核心API</a></li>
<li class="toctree-l1"><a class="reference internal" href="signals.html">信号</a></li>
<li class="toctree-l1"><a class="reference internal" href="exporters.html">条目导出器</a></li>
</ul>
<p class="caption"><span class="caption-text">其余所有</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../news.html">发行说明</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">为 Scrapy 贡献</a></li>
<li class="toctree-l1"><a class="reference internal" href="../versioning.html">版本控制和API稳定性</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Scrapy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>Feed 导出</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="feed-exports">
<span id="topics-feed-exports"></span><h1>Feed 导出<a class="headerlink" href="#feed-exports" title="永久链接至标题">¶</a></h1>
<p>在实现scraper时，最经常需要的功能之一是能够正确地存储被抓取的数据，这通常意味着用被抓取的数据（通常称为“导出提要”）生成一个“导出文件”，供其他系统使用。</p>
<p>Scrapy在提要导出中提供了开箱即用的功能，它允许您使用多种序列化格式和存储后端来生成带有所刮取项的提要。</p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-1466963416408457"
     data-ad-slot="8850786025"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<div class="section" id="serialization-formats">
<span id="topics-feed-format"></span><h2>序列化格式<a class="headerlink" href="#serialization-formats" title="永久链接至标题">¶</a></h2>
<p>为了序列化 爬取  的数据，提要导出使用 <a class="reference internal" href="exporters.html#topics-exporters"><span class="std std-ref">Item exporters</span></a> . 开箱即用支持这些格式：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#topics-feed-format-json"><span class="std std-ref">JSON</span></a></p></li>
<li><p><a class="reference internal" href="#topics-feed-format-jsonlines"><span class="std std-ref">杰森线</span></a></p></li>
<li><p><a class="reference internal" href="#topics-feed-format-csv"><span class="std std-ref">CSV</span></a></p></li>
<li><p><a class="reference internal" href="#topics-feed-format-xml"><span class="std std-ref">XML</span></a></p></li>
</ul>
</div></blockquote>
<p>但是您也可以通过 <a class="reference internal" href="#std-setting-FEED_EXPORTERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORTERS</span></code></a> 设置。</p>
<div class="section" id="json">
<span id="topics-feed-format-json"></span><h3>JSON<a class="headerlink" href="#json" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">json</span></code></p></li>
<li><p>出口商： <a class="reference internal" href="exporters.html#scrapy.exporters.JsonItemExporter" title="scrapy.exporters.JsonItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">JsonItemExporter</span></code></a></p></li>
<li><p>见 <a class="reference internal" href="exporters.html#json-with-large-data"><span class="std std-ref">this warning</span></a> 如果您使用的是大型提要的JSON。</p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="json-lines">
<span id="topics-feed-format-jsonlines"></span><h3>杰森线<a class="headerlink" href="#json-lines" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">jsonlines</span></code></p></li>
<li><p>出口商： <a class="reference internal" href="exporters.html#scrapy.exporters.JsonLinesItemExporter" title="scrapy.exporters.JsonLinesItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">JsonLinesItemExporter</span></code></a></p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="csv">
<span id="topics-feed-format-csv"></span><h3>CSV<a class="headerlink" href="#csv" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">csv</span></code></p></li>
<li><p>出口商： <a class="reference internal" href="exporters.html#scrapy.exporters.CsvItemExporter" title="scrapy.exporters.CsvItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">CsvItemExporter</span></code></a></p></li>
<li><p>指定要导出的列及其顺序的步骤使用 <a class="reference internal" href="#std-setting-FEED_EXPORT_FIELDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_FIELDS</span></code></a> . 其他feed导出器也可以使用此选项，但对于csv很重要，因为与许多其他导出格式不同，csv使用固定头。</p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="xml">
<span id="topics-feed-format-xml"></span><h3>XML<a class="headerlink" href="#xml" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">xml</span></code></p></li>
<li><p>出口商： <a class="reference internal" href="exporters.html#scrapy.exporters.XmlItemExporter" title="scrapy.exporters.XmlItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">XmlItemExporter</span></code></a></p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="pickle">
<span id="topics-feed-format-pickle"></span><h3>泡菜<a class="headerlink" href="#pickle" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">pickle</span></code></p></li>
<li><p>出口商： <a class="reference internal" href="exporters.html#scrapy.exporters.PickleItemExporter" title="scrapy.exporters.PickleItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PickleItemExporter</span></code></a></p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="marshal">
<span id="topics-feed-format-marshal"></span><h3>元帅<a class="headerlink" href="#marshal" title="永久链接至标题">¶</a></h3>
<blockquote>
<div><ul class="simple">
<li><p>价值 <code class="docutils literal notranslate"><span class="pre">format</span></code> 关键在 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置： <code class="docutils literal notranslate"><span class="pre">marshal</span></code></p></li>
<li><p>出口商： <code class="xref py py-class docutils literal notranslate"><span class="pre">MarshalItemExporter</span></code></p></li>
</ul>
</div></blockquote>
</div>
</div>
<div class="section" id="storages">
<span id="topics-feed-storage"></span><h2>储藏室<a class="headerlink" href="#storages" title="永久链接至标题">¶</a></h2>
<p>使用提要导出时，可以使用一个或多个定义存储提要的位置 <a class="reference external" href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier">URIs</a> （通过 <a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> 设置）。提要导出支持由URI方案定义的多个存储后端类型。</p>
<p>开箱支持的存储后端包括：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#topics-feed-storage-fs"><span class="std std-ref">本地文件系统</span></a></p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-ftp"><span class="std std-ref">FTP</span></a></p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-s3"><span class="std std-ref">S3</span></a> （需要 <a class="reference external" href="https://github.com/boto/botocore">botocore</a>)</p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-gcs"><span class="std std-ref">谷歌云存储（GCS）</span></a> （需要 <a class="reference external" href="https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python">google-cloud-storage</a> ）</p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-stdout"><span class="std std-ref">标准输出</span></a></p></li>
</ul>
</div></blockquote>
<p>如果所需的外部库不可用，则某些存储后端可能不可用。例如，只有在 <a class="reference external" href="https://github.com/boto/botocore">botocore</a> 库已安装。</p>
</div>
<div class="section" id="storage-uri-parameters">
<span id="topics-feed-uri-params"></span><h2>存储URI参数<a class="headerlink" href="#storage-uri-parameters" title="永久链接至标题">¶</a></h2>
<p>存储URI还可以包含在创建源时被替换的参数。这些参数是：</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">%(time)s</span></code> -在创建源时被时间戳替换</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">%(name)s</span></code> -替换为蜘蛛名称</p></li>
</ul>
</div></blockquote>
<p>任何其他命名参数都将被同名的spider属性替换。例如， <code class="docutils literal notranslate"><span class="pre">%(site_id)s</span></code> 将被替换为 <code class="docutils literal notranslate"><span class="pre">spider.site_id</span></code> 属性为正在创建源的时刻。</p>
<p>下面举例说明：</p>
<blockquote>
<div><ul class="simple">
<li><p>使用每个spider一个目录存储在ftp中：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">ftp://user:password&#64;ftp.example.com/scraping/feeds/%(name)s/%(time)s.json</span></code></p></li>
</ul>
</li>
<li><p>使用每个spider一个目录存储在S3中：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">s3://mybucket/scraping/feeds/%(name)s/%(time)s.json</span></code></p></li>
</ul>
</li>
</ul>
</div></blockquote>
</div>
<div class="section" id="storage-backends">
<span id="topics-feed-storage-backends"></span><h2>存储后端<a class="headerlink" href="#storage-backends" title="永久链接至标题">¶</a></h2>
<div class="section" id="local-filesystem">
<span id="topics-feed-storage-fs"></span><h3>本地文件系统<a class="headerlink" href="#local-filesystem" title="永久链接至标题">¶</a></h3>
<p>源存储在本地文件系统中。</p>
<blockquote>
<div><ul class="simple">
<li><p>URI方案： <code class="docutils literal notranslate"><span class="pre">file</span></code></p></li>
<li><p>示例性URI： <code class="docutils literal notranslate"><span class="pre">file:///tmp/export.csv</span></code></p></li>
<li><p>所需外部库：无</p></li>
</ul>
</div></blockquote>
<p>请注意，对于本地文件系统存储（仅限），如果您指定类似 <code class="docutils literal notranslate"><span class="pre">/tmp/export.csv</span></code> . 不过，这只在UNIX系统上工作。</p>
</div>
<div class="section" id="ftp">
<span id="topics-feed-storage-ftp"></span><h3>FTP<a class="headerlink" href="#ftp" title="永久链接至标题">¶</a></h3>
<p>这些提要存储在FTP服务器中。</p>
<blockquote>
<div><ul class="simple">
<li><p>URI方案： <code class="docutils literal notranslate"><span class="pre">ftp</span></code></p></li>
<li><p>示例性URI： <code class="docutils literal notranslate"><span class="pre">ftp://user:pass&#64;ftp.example.com/path/to/export.csv</span></code></p></li>
<li><p>所需外部库：无</p></li>
</ul>
</div></blockquote>
<p>ftp支持两种不同的连接模式： <a class="reference external" href="https://stackoverflow.com/a/1699163">active or passive</a> .默认情况下，Scrapy使用被动连接模式。要使用活动连接模式，请设置 <a class="reference internal" href="#std-setting-FEED_STORAGE_FTP_ACTIVE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGE_FTP_ACTIVE</span></code></a> 设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code> .</p>
<p>此存储后端使用 <a class="reference internal" href="#delayed-file-delivery"><span class="std std-ref">delayed file delivery</span></a> .</p>
</div>
<div class="section" id="s3">
<span id="topics-feed-storage-s3"></span><h3>S3<a class="headerlink" href="#s3" title="永久链接至标题">¶</a></h3>
<p>源存储在 <a class="reference external" href="https://aws.amazon.com/s3/">Amazon S3</a> .</p>
<blockquote>
<div><ul class="simple">
<li><p>URI方案： <code class="docutils literal notranslate"><span class="pre">s3</span></code></p></li>
<li><p>URI示例：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">s3://mybucket/path/to/export.csv</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">s3://aws_key:aws_secret&#64;mybucket/path/to/export.csv</span></code></p></li>
</ul>
</li>
<li><p>所需的外部库： <a class="reference external" href="https://github.com/boto/botocore">botocore</a></p></li>
</ul>
</div></blockquote>
<p>AWS凭证可以作为用户/密码在URI中传递，也可以通过以下设置传递：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="settings.html#std-setting-AWS_ACCESS_KEY_ID"><code class="xref std std-setting docutils literal notranslate"><span class="pre">AWS_ACCESS_KEY_ID</span></code></a></p></li>
<li><p><a class="reference internal" href="settings.html#std-setting-AWS_SECRET_ACCESS_KEY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">AWS_SECRET_ACCESS_KEY</span></code></a></p></li>
</ul>
</div></blockquote>
<p>还可以使用此设置为导出的源定义自定义ACL：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#std-setting-FEED_STORAGE_S3_ACL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGE_S3_ACL</span></code></a></p></li>
</ul>
</div></blockquote>
<p>此存储后端使用 <a class="reference internal" href="#delayed-file-delivery"><span class="std std-ref">delayed file delivery</span></a> .</p>
</div>
<div class="section" id="google-cloud-storage-gcs">
<span id="topics-feed-storage-gcs"></span><h3>谷歌云存储（GCS）<a class="headerlink" href="#google-cloud-storage-gcs" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified added">2.3 新版功能.</span></p>
</div>
<p>源存储在 <a class="reference external" href="https://cloud.google.com/storage/">Google Cloud Storage</a> .</p>
<blockquote>
<div><ul class="simple">
<li><p>URI方案： <code class="docutils literal notranslate"><span class="pre">gs</span></code></p></li>
<li><p>URI示例：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">gs://mybucket/path/to/export.csv</span></code></p></li>
</ul>
</li>
<li><p>所需的外部库： <a class="reference external" href="https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python">google-cloud-storage</a> .</p></li>
</ul>
</div></blockquote>
<p>有关身份验证的详细信息，请参阅 <a class="reference external" href="https://cloud.google.com/docs/authentication/production">Google Cloud documentation</a> .</p>
<p>你可以设置一个 <em>项目标识</em> 和 <em>访问控制列表（ACL）</em> 通过以下设置：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="settings.html#std-setting-FEED_STORAGE_GCS_ACL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGE_GCS_ACL</span></code></a></p></li>
<li><p><a class="reference internal" href="settings.html#std-setting-GCS_PROJECT_ID"><code class="xref std std-setting docutils literal notranslate"><span class="pre">GCS_PROJECT_ID</span></code></a></p></li>
</ul>
</div></blockquote>
<p>此存储后端使用 <a class="reference internal" href="#delayed-file-delivery"><span class="std std-ref">delayed file delivery</span></a> .</p>
</div>
<div class="section" id="standard-output">
<span id="topics-feed-storage-stdout"></span><h3>标准输出<a class="headerlink" href="#standard-output" title="永久链接至标题">¶</a></h3>
<p>进料被写入 Scrapy  处理的标准输出。</p>
<blockquote>
<div><ul class="simple">
<li><p>URI方案： <code class="docutils literal notranslate"><span class="pre">stdout</span></code></p></li>
<li><p>示例性URI： <code class="docutils literal notranslate"><span class="pre">stdout:</span></code></p></li>
<li><p>所需外部库：无</p></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="delayed-file-delivery">
<span id="id1"></span><h3>延迟文件传递<a class="headerlink" href="#delayed-file-delivery" title="永久链接至标题">¶</a></h3>
<p>如上所述，所述的一些存储后端使用延迟的文件传递。</p>
<p>这些存储后端不会将项上载到提要URI，因为这些项是被刮取的。相反，Scrapy将项目写入一个临时本地文件，只有当所有文件内容都被写入（即在爬网结束时），该文件才会上载到提要URI。</p>
<p>如果要在使用这些存储后端之一时提前开始项目传递，请使用 <a class="reference internal" href="#std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_BATCH_ITEM_COUNT</span></code></a> 将输出项拆分为多个文件，每个文件具有指定的最大项数。这样，一旦文件达到最大项数，该文件就被传递到提要URI，从而允许条目传递在爬网结束之前开始。</p>
</div>
</div>
<div class="section" id="settings">
<h2>设置<a class="headerlink" href="#settings" title="永久链接至标题">¶</a></h2>
<p>以下是用于配置源导出的设置：</p>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="#std-setting-FEEDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEEDS</span></code></a> （强制性）</p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_EXPORT_ENCODING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_ENCODING</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_STORE_EMPTY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORE_EMPTY</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_EXPORT_FIELDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_FIELDS</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_EXPORT_INDENT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_INDENT</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_STORAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGES</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_STORAGE_FTP_ACTIVE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGE_FTP_ACTIVE</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_STORAGE_S3_ACL"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGE_S3_ACL</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_EXPORTERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORTERS</span></code></a></p></li>
<li><p><a class="reference internal" href="#std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_BATCH_ITEM_COUNT</span></code></a></p></li>
</ul>
</div></blockquote>
<div class="section" id="feeds">
<span id="std-setting-FEEDS"></span><span id="std:setting-FEEDS"></span><h3>FEEDS<a class="headerlink" href="#feeds" title="永久链接至标题">¶</a></h3>
<div class="versionadded">
<p><span class="versionmodified added">2.1 新版功能.</span></p>
</div>
<p>违约： <code class="docutils literal notranslate"><span class="pre">{{}}</span></code></p>
<p>一个字典，其中每个键都是一个feed URI（或 <a class="reference external" href="https://docs.python.org/3/library/pathlib.html#pathlib.Path" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> 对象），每个值都是一个嵌套字典，其中包含特定提要的配置参数。</p>
<p>启用提要导出功能需要此设置。</p>
<p>见 <a class="reference internal" href="#topics-feed-storage-backends"><span class="std std-ref">存储后端</span></a> 用于支持的URI方案。</p>
<p>例如：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;items.json&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;format&#39;</span><span class="p">:</span> <span class="s1">&#39;json&#39;</span><span class="p">,</span>
        <span class="s1">&#39;encoding&#39;</span><span class="p">:</span> <span class="s1">&#39;utf8&#39;</span><span class="p">,</span>
        <span class="s1">&#39;store_empty&#39;</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
        <span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s1">&#39;indent&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
        <span class="s1">&#39;item_export_kwargs&#39;</span><span class="p">:</span> <span class="p">{</span>
           <span class="s1">&#39;export_empty_fields&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
        <span class="p">},</span>
    <span class="p">},</span>
    <span class="s1">&#39;/home/user/documents/items.xml&#39;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s1">&#39;format&#39;</span><span class="p">:</span> <span class="s1">&#39;xml&#39;</span><span class="p">,</span>
        <span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="s1">&#39;price&#39;</span><span class="p">],</span>
        <span class="s1">&#39;encoding&#39;</span><span class="p">:</span> <span class="s1">&#39;latin1&#39;</span><span class="p">,</span>
        <span class="s1">&#39;indent&#39;</span><span class="p">:</span> <span class="mi">8</span><span class="p">,</span>
    <span class="p">},</span>
    <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;items.csv&#39;</span><span class="p">):</span> <span class="p">{</span>
        <span class="s1">&#39;format&#39;</span><span class="p">:</span> <span class="s1">&#39;csv&#39;</span><span class="p">,</span>
        <span class="s1">&#39;fields&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;price&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">],</span>
    <span class="p">},</span>
<span class="p">}</span>
</pre></div>
</div>
<p>以下是接受的键和设置的列表，如果没有为特定的源定义提供该键，则该设置用作回退值：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">format</span></code> ： <a class="reference internal" href="#topics-feed-format"><span class="std std-ref">serialization format</span></a> .</p>
<p>此设置是必需的，没有回退值。</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">batch_item_count</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_BATCH_ITEM_COUNT</span></code></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">encoding</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_EXPORT_ENCODING"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_ENCODING</span></code></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">fields</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_EXPORT_FIELDS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_FIELDS</span></code></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">indent</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_EXPORT_INDENT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_INDENT</span></code></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">item_export_kwargs</span></code>: <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> 对应的关键字参数 <a class="reference internal" href="exporters.html#topics-exporters"><span class="std std-ref">item exporter class</span></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">overwrite</span></code> ：如果文件已存在，是否覆盖该文件 (<code class="docutils literal notranslate"><span class="pre">True</span></code> )或附加到其内容中 (<code class="docutils literal notranslate"><span class="pre">False</span></code> ）</p>
<p>默认值取决于 <a class="reference internal" href="#topics-feed-storage-backends"><span class="std std-ref">storage backend</span></a> ：</p>
<ul>
<li><p><a class="reference internal" href="#topics-feed-storage-fs"><span class="std std-ref">本地文件系统</span></a>: <code class="docutils literal notranslate"><span class="pre">False</span></code></p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-ftp"><span class="std std-ref">FTP</span></a>: <code class="docutils literal notranslate"><span class="pre">True</span></code></p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>某些FTP服务器可能不支持附加到文件（ <code class="docutils literal notranslate"><span class="pre">APPE</span></code> FTP命令）。</p>
</div>
</li>
<li><p><a class="reference internal" href="#topics-feed-storage-s3"><span class="std std-ref">S3</span></a> ： <code class="docutils literal notranslate"><span class="pre">True</span></code> （附加 <a class="reference external" href="https://forums.aws.amazon.com/message.jspa?messageID=540395">is not supported</a> ）</p></li>
<li><p><a class="reference internal" href="#topics-feed-storage-stdout"><span class="std std-ref">标准输出</span></a> ： <code class="docutils literal notranslate"><span class="pre">False</span></code> （不支持覆盖）</p></li>
</ul>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">store_empty</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_STORE_EMPTY"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORE_EMPTY</span></code></a> .</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">uri_params</span></code> ：回到 <a class="reference internal" href="#std-setting-FEED_URI_PARAMS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_URI_PARAMS</span></code></a> .</p></li>
</ul>
</div>
<div class="section" id="feed-export-encoding">
<span id="std-setting-FEED_EXPORT_ENCODING"></span><span id="std:setting-FEED_EXPORT_ENCODING"></span><h3>FEED_EXPORT_ENCODING<a class="headerlink" href="#feed-export-encoding" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>要用于源的编码。</p>
<p>如果未设置或设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> （默认）它对除JSON输出外的所有内容都使用UTF-8，JSON输出使用安全的数字编码。 (<code class="docutils literal notranslate"><span class="pre">\uXXXX</span></code> 序列）出于历史原因。</p>
<p>使用 <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> 如果您也想要为JSON使用UTF-8。</p>
</div>
<div class="section" id="feed-export-fields">
<span id="std-setting-FEED_EXPORT_FIELDS"></span><span id="std:setting-FEED_EXPORT_FIELDS"></span><h3>FEED_EXPORT_FIELDS<a class="headerlink" href="#feed-export-fields" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>要导出的字段列表，可选。例子： <code class="docutils literal notranslate"><span class="pre">FEED_EXPORT_FIELDS</span> <span class="pre">=</span> <span class="pre">[&quot;foo&quot;,</span> <span class="pre">&quot;bar&quot;,</span> <span class="pre">&quot;baz&quot;]</span></code> .</p>
<p>使用feed_export_fields选项定义要导出的字段及其顺序。</p>
<p>当FEED_EXPORT_FIELDS为空或None（默认值）时，Scrapy使用中定义的字段 <a class="reference internal" href="items.html#topics-items"><span class="std std-ref">item objects</span></a> 你的蜘蛛屈服了。</p>
<p>如果导出器需要一组固定的字段（这是 <a class="reference internal" href="#topics-feed-format-csv"><span class="std std-ref">CSV</span></a> export format）和feed_export_字段为空或无，然后scrapy尝试从导出的数据中推断字段名-当前它使用第一个项目中的字段名。</p>
</div>
<div class="section" id="feed-export-indent">
<span id="std-setting-FEED_EXPORT_INDENT"></span><span id="std:setting-FEED_EXPORT_INDENT"></span><h3>FEED_EXPORT_INDENT<a class="headerlink" href="#feed-export-indent" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
<p>用于在每个级别上缩进输出的空间量。如果 <code class="docutils literal notranslate"><span class="pre">FEED_EXPORT_INDENT</span></code> 是非负整数，则数组元素和对象成员将以该缩进级别进行漂亮打印。缩进量 <code class="docutils literal notranslate"><span class="pre">0</span></code> （默认值）或负数，将把每个项目放到一个新行上。 <code class="docutils literal notranslate"><span class="pre">None</span></code> 选择最紧凑的表示形式。</p>
<p>当前仅由执行 <a class="reference internal" href="exporters.html#scrapy.exporters.JsonItemExporter" title="scrapy.exporters.JsonItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">JsonItemExporter</span></code></a> 和 <a class="reference internal" href="exporters.html#scrapy.exporters.XmlItemExporter" title="scrapy.exporters.XmlItemExporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">XmlItemExporter</span></code></a> ，即当您要导出到 <code class="docutils literal notranslate"><span class="pre">.json</span></code> 或 <code class="docutils literal notranslate"><span class="pre">.xml</span></code> .</p>
</div>
<div class="section" id="feed-store-empty">
<span id="std-setting-FEED_STORE_EMPTY"></span><span id="std:setting-FEED_STORE_EMPTY"></span><h3>FEED_STORE_EMPTY<a class="headerlink" href="#feed-store-empty" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>是否导出空源（即没有项的源）。</p>
</div>
<div class="section" id="feed-storages">
<span id="std-setting-FEED_STORAGES"></span><span id="std:setting-FEED_STORAGES"></span><h3>FEED_STORAGES<a class="headerlink" href="#feed-storages" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">{{}}</span></code></p>
<p>包含项目支持的其他提要存储后端的dict。键是URI方案，值是指向存储类的路径。</p>
</div>
<div class="section" id="feed-storage-ftp-active">
<span id="std-setting-FEED_STORAGE_FTP_ACTIVE"></span><span id="std:setting-FEED_STORAGE_FTP_ACTIVE"></span><h3>FEED_STORAGE_FTP_ACTIVE<a class="headerlink" href="#feed-storage-ftp-active" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">False</span></code></p>
<p>将源导出到FTP服务器时是否使用活动连接模式 (<code class="docutils literal notranslate"><span class="pre">True</span></code> ）或者使用被动连接模式 (<code class="docutils literal notranslate"><span class="pre">False</span></code> ，默认）。</p>
<p>有关ftp连接模式的信息，请参阅 <a class="reference external" href="https://stackoverflow.com/a/1699163">What is the difference between active and passive FTP?</a> .</p>
</div>
<div class="section" id="feed-storage-s3-acl">
<span id="std-setting-FEED_STORAGE_S3_ACL"></span><span id="std:setting-FEED_STORAGE_S3_ACL"></span><h3>FEED_STORAGE_S3_ACL<a class="headerlink" href="#feed-storage-s3-acl" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">''</span></code> （空字符串）</p>
<p>包含项目导出到AmazonS3的源的自定义ACL的字符串。</p>
<p>有关可用值的完整列表，请访问 <a class="reference external" href="https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl">Canned ACL</a> 亚马逊S3文档部分。</p>
</div>
<div class="section" id="feed-storages-base">
<span id="std-setting-FEED_STORAGES_BASE"></span><span id="std:setting-FEED_STORAGES_BASE"></span><h3>FEED_STORAGES_BASE<a class="headerlink" href="#feed-storages-base" title="永久链接至标题">¶</a></h3>
<p>违约：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.extensions.feedexport.FileFeedStorage&#39;</span><span class="p">,</span>
    <span class="s1">&#39;file&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.extensions.feedexport.FileFeedStorage&#39;</span><span class="p">,</span>
    <span class="s1">&#39;stdout&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.extensions.feedexport.StdoutFeedStorage&#39;</span><span class="p">,</span>
    <span class="s1">&#39;s3&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.extensions.feedexport.S3FeedStorage&#39;</span><span class="p">,</span>
    <span class="s1">&#39;ftp&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.extensions.feedexport.FTPFeedStorage&#39;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>包含由Scrapy支持的内置提要存储后端的dict。您可以通过分配 <code class="docutils literal notranslate"><span class="pre">None</span></code> 到他们的URI方案 <a class="reference internal" href="#std-setting-FEED_STORAGES"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_STORAGES</span></code></a> . 例如，要禁用内置FTP存储后端（不替换），请将其放入 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> ：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FEED_STORAGES</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;ftp&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="feed-exporters">
<span id="std-setting-FEED_EXPORTERS"></span><span id="std:setting-FEED_EXPORTERS"></span><h3>FEED_EXPORTERS<a class="headerlink" href="#feed-exporters" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">{{}}</span></code></p>
<p>包含项目支持的其他导出器的dict。键是序列化格式，值是指向 <a class="reference internal" href="exporters.html#topics-exporters"><span class="std std-ref">Item exporter</span></a> 类。</p>
</div>
<div class="section" id="feed-exporters-base">
<span id="std-setting-FEED_EXPORTERS_BASE"></span><span id="std:setting-FEED_EXPORTERS_BASE"></span><h3>FEED_EXPORTERS_BASE<a class="headerlink" href="#feed-exporters-base" title="永久链接至标题">¶</a></h3>
<p>违约：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;json&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.JsonItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;jsonlines&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.JsonLinesItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;jl&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.JsonLinesItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;csv&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.CsvItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;xml&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.XmlItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;marshal&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.MarshalItemExporter&#39;</span><span class="p">,</span>
    <span class="s1">&#39;pickle&#39;</span><span class="p">:</span> <span class="s1">&#39;scrapy.exporters.PickleItemExporter&#39;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
<p>包含由Scrapy支持的内置饲料导出器的dict。您可以通过分配 <code class="docutils literal notranslate"><span class="pre">None</span></code> 到其序列化格式 <a class="reference internal" href="#std-setting-FEED_EXPORTERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORTERS</span></code></a> . 例如，要禁用内置的csv导出器（不替换），请将其放入 <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> ：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FEED_EXPORTERS</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;csv&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="feed-export-batch-item-count">
<span id="std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"></span><span id="std:setting-FEED_EXPORT_BATCH_ITEM_COUNT"></span><h3>FEED_EXPORT_BATCH_ITEM_COUNT<a class="headerlink" href="#feed-export-batch-item-count" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">0</span></code></p>
<p>如果分配了一个大于 <code class="docutils literal notranslate"><span class="pre">0</span></code> ，Scrapy生成多个输出文件，每个输出文件中最多存储指定数量的项。</p>
<p>生成多个输出文件时，必须在提要URI中至少使用以下一个占位符来指示如何生成不同的输出文件名：</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">%(batch_time)s</span></code> -在创建源时被时间戳替换（例如。 <code class="docutils literal notranslate"><span class="pre">2020-03-28T14-45-08.237134</span></code> ）</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">%(batch_id)d</span></code> -替换为批处理的从1开始的序列号。</p>
<p>使用 <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#old-string-formatting" title="(在 Python v3.9)"><span class="xref std std-ref">printf-style string formatting</span></a> 改变数字格式。例如，要根据需要引入前导零，使批次标识为5位数字，请使用 <code class="docutils literal notranslate"><span class="pre">%(batch_id)05d</span></code> （例如） <code class="docutils literal notranslate"><span class="pre">3</span></code> 变成 <code class="docutils literal notranslate"><span class="pre">00003</span></code> ， <code class="docutils literal notranslate"><span class="pre">123</span></code> 变成 <code class="docutils literal notranslate"><span class="pre">00123</span></code> ）</p>
</li>
</ul>
<p>例如，如果您的设置包括：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">FEED_EXPORT_BATCH_ITEM_COUNT</span> <span class="o">=</span> <span class="mi">100</span>
</pre></div>
</div>
<p>你的呢 <a class="reference internal" href="commands.html#std-command-crawl"><code class="xref std std-command docutils literal notranslate"><span class="pre">crawl</span></code></a> 命令行是：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">scrapy</span> <span class="n">crawl</span> <span class="n">spidername</span> <span class="o">-</span><span class="n">o</span> <span class="s2">&quot;dirname/</span><span class="si">%(batch_id)d</span><span class="s2">-filename</span><span class="si">%(batch_time)s</span><span class="s2">.json&quot;</span>
</pre></div>
</div>
<p>上面的命令行可以生成如下目录树：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">-&gt;</span><span class="n">projectname</span>
<span class="o">--&gt;</span><span class="n">dirname</span>
<span class="o">---&gt;</span><span class="mi">1</span><span class="o">-</span><span class="n">filename2020</span><span class="o">-</span><span class="mi">03</span><span class="o">-</span><span class="mi">28</span><span class="n">T14</span><span class="o">-</span><span class="mi">45</span><span class="o">-</span><span class="mf">08.237134</span><span class="o">.</span><span class="n">json</span>
<span class="o">---&gt;</span><span class="mi">2</span><span class="o">-</span><span class="n">filename2020</span><span class="o">-</span><span class="mi">03</span><span class="o">-</span><span class="mi">28</span><span class="n">T14</span><span class="o">-</span><span class="mi">45</span><span class="o">-</span><span class="mf">09.148903</span><span class="o">.</span><span class="n">json</span>
<span class="o">---&gt;</span><span class="mi">3</span><span class="o">-</span><span class="n">filename2020</span><span class="o">-</span><span class="mi">03</span><span class="o">-</span><span class="mi">28</span><span class="n">T14</span><span class="o">-</span><span class="mi">45</span><span class="o">-</span><span class="mf">10.046092</span><span class="o">.</span><span class="n">json</span>
</pre></div>
</div>
<p>其中第一个和第二个文件正好包含100个项目。最后一个包含100个项目或更少。</p>
</div>
<div class="section" id="feed-uri-params">
<span id="std-setting-FEED_URI_PARAMS"></span><span id="std:setting-FEED_URI_PARAMS"></span><h3>FEED_URI_PARAMS<a class="headerlink" href="#feed-uri-params" title="永久链接至标题">¶</a></h3>
<p>违约： <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
<p>包含函数导入路径的字符串，用于设置要应用的参数 <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#old-string-formatting" title="(在 Python v3.9)"><span class="xref std std-ref">printf-style string formatting</span></a> 到源URI。</p>
<p>函数签名应如下所示：</p>
<dl class="py function">
<dt id="scrapy.extensions.feedexport.uri_params">
<code class="sig-prename descclassname">scrapy.extensions.feedexport.</code><code class="sig-name descname">uri_params</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">params</span></em>, <em class="sig-param"><span class="n">spider</span></em><span class="sig-paren">)</span><a class="headerlink" href="#scrapy.extensions.feedexport.uri_params" title="永久链接至目标">¶</a></dt>
<dd><p>返回A <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(在 Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> 要应用于提要URI的键值对 <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#old-string-formatting" title="(在 Python v3.9)"><span class="xref std std-ref">printf-style string formatting</span></a> .</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>params</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(在 Python v3.9)"><em>dict</em></a>) -- 特定的默认键值对：- <code class="docutils literal notranslate"><span class="pre">batch_id</span></code>: ID of the file batch. See     <a class="reference internal" href="#std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_BATCH_ITEM_COUNT</span></code></a>.      If <a class="reference internal" href="#std-setting-FEED_EXPORT_BATCH_ITEM_COUNT"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_EXPORT_BATCH_ITEM_COUNT</span></code></a> is <code class="docutils literal notranslate"><span class="pre">0</span></code>, <code class="docutils literal notranslate"><span class="pre">batch_id</span></code>     is always <code class="docutils literal notranslate"><span class="pre">1</span></code>.  -   <code class="docutils literal notranslate"><span class="pre">batch_time</span></code>: UTC date and time, in ISO format with <code class="docutils literal notranslate"><span class="pre">:</span></code>     replaced with `` -<code class="docutils literal notranslate"><span class="pre">.</span>&#160;&#160;&#160;&#160;&#160; <span class="pre">看到了吗</span> <span class="pre">:setting:`FEED_EXPORT_BATCH_ITEM_COUNT`</span> <span class="pre">.</span>&#160; <span class="pre">-</span> <span class="pre">``time</span></code> ： <code class="docutils literal notranslate"><span class="pre">batch_time</span></code> ，微秒设置为 <code class="docutils literal notranslate"><span class="pre">0</span></code> .</p></li>
<li><p><strong>spider</strong> (<a class="reference internal" href="spiders.html#scrapy.spiders.Spider" title="scrapy.spiders.Spider"><em>scrapy.spiders.Spider</em></a>) -- 源蜘蛛的饲料项目</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<p>例如，包括 <a class="reference internal" href="spiders.html#scrapy.spiders.Spider.name" title="scrapy.spiders.Spider.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> 源URI中源蜘蛛的：</p>
<ol class="arabic">
<li><p>在项目的某个地方定义以下函数：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># myproject/utils.py</span>
<span class="k">def</span> <span class="nf">uri_params</span><span class="p">(</span><span class="n">params</span><span class="p">,</span> <span class="n">spider</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">{</span><span class="o">**</span><span class="n">params</span><span class="p">,</span> <span class="s1">&#39;spider_name&#39;</span><span class="p">:</span> <span class="n">spider</span><span class="o">.</span><span class="n">name</span><span class="p">}</span>
</pre></div>
</div>
</li>
<li><p>Point <a class="reference internal" href="#std-setting-FEED_URI_PARAMS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">FEED_URI_PARAMS</span></code></a> 到您设置中的函数：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># myproject/settings.py</span>
<span class="n">FEED_URI_PARAMS</span> <span class="o">=</span> <span class="s1">&#39;myproject.utils.uri_params&#39;</span>
</pre></div>
</div>
</li>
<li><p>使用 <code class="docutils literal notranslate"><span class="pre">%(spider_name)s</span></code> 在你的源URI中：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">scrapy</span> <span class="n">crawl</span> <span class="o">&lt;</span><span class="n">spider_name</span><span class="o">&gt;</span> <span class="o">-</span><span class="n">o</span> <span class="s2">&quot;</span><span class="si">%(spider_name)s</span><span class="s2">.jl&quot;</span>
</pre></div>
</div>
</li>
</ol>
</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="request-response.html" class="btn btn-neutral float-right" title="请求和响应" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="item-pipeline.html" class="btn btn-neutral float-left" title="项目管道" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        
        &copy; 版权所有 2008–2020, Scrapy developers
      <span class="lastupdated">
        最后更新于 10月 18, 2020.
      </span>

    </p>
  </div>
    
    
    
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
  
 
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
analytics.load("8UDQfnf3cyFSTsM4YANnW5sXmgZVILbA");
analytics.page();
}}();

analytics.ready(function () {
    ga('require', 'linker');
    ga('linker:autoLink', ['scrapinghub.com', 'crawlera.com']);
});
</script>


</body>
</html>